﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL;
using System.Web;

namespace logic
{
    public class loginLog
    {
        public static DataSet select(string where, string orderby, int pagesize, int pageindex)
        {
            return DbHelper.ExecuteDataSetPageSize("*", "vw_LoginLog_list", where, "logId", orderby, pagesize, pageindex);
        }

        public static void insertFade(int userId,string userType,string sessionId)
        {
            LoginLogEntity entity = new LoginLogEntity()
            {
                UserId=userId,
                UserType=userType,
                Ip=GetClientIP(),
                SessionId=sessionId
            };

            LoginLog.insert(entity);
        }

        public static void insert(LoginLogEntity entity)
        {
            LoginLog.insert(entity);
        }

        public static void update(string sessionId,DateTime offLineDate)
        {
            LoginLog.update(sessionId,offLineDate);
        }

        public static string GetClientIP()
        {
            string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (null == result || result == string.Empty)
            {
                result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }

            if (null == result || result == string.Empty)
            {
                result = HttpContext.Current.Request.UserHostAddress;
            }
            return result;
        }
    }
}
